package cn01;

//猜数字

import java.util.Random;
import java.util.Scanner;

public class test02 {
    public static void main(String[] args) {
        Random r = new Random();
        int x = r.nextInt(100);
        Scanner sc = new Scanner(System.in);
        int count =0;
        for (int i = 0; i < 100; i++) {
            System.out.println("请输入你猜的数字：");
            int a = sc.nextInt();
            if (a > x) {
                System.out.println("你猜的大了");
            } else if (a < x) {
                System.out.println("你猜的小了");
            } else {
                System.out.println("恭喜你猜对了");
                break;
            }
            count++;
        }
        System.out.println("总共猜了"+count+"次");
    }
}